<template>
  <div class="container">
    <topTitle :titleText="titleText"></topTitle>
    <div class="mainCon">
      <el-row class="toolbar searchInputWidth" style="padding-bottom: 0">
        <el-form :inline="true" :model="filterField" ref="searchConditions">
          <el-form-item label="项目名称" class="row-padding-bottom">
            <el-input
              v-model="filterField.projectName"
              placeholder="请输入项目名称"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item label="区域" class="row-padding-bottom">
            <el-cascader
              ref="manageArea"
              v-model="areaId"
              :options="areasOptions"
              @change="getAreaId"
              clearable
              filterable
              :props="{ checkStrictly: true }"
            ></el-cascader>
          </el-form-item>
          <el-form-item label="行业" class="row-padding-bottom">
            <el-select
              v-model="filterField.industryId"
              filterable
              placeholder="请选择"
              clearable
            >
              <el-option
                v-for="item in industryOptions"
                :key="item.code"
                :label="item.name"
                :value="item.code"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="专户账号" class="row-padding-bottom">
            <el-input
              v-model="filterField.account"
              placeholder="请输入专户账号"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item label="开户银行" class="row-padding-bottom">
            <el-select
              v-model="filterField.bankId"
              filterable
              placeholder="请选择开户银行"
              clearable
            >
              <el-option
                v-for="item in bankOptions"
                :key="item.code"
                :label="item.name"
                :value="item.code"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="icon iconfont iconchazhao1"
              @click="searchList"
              class="commonBtn"
            ></el-button>
          </el-form-item>
        </el-form>
      </el-row>

      <el-table
        :data="tableList"
        v-loading="loading"
        :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
        highlight-current-row
        stripe
        style="border: 1px solid #dfe6ec"
      >
        <el-table-column prop="projectName" label="项目名称"></el-table-column>
        <el-table-column
          prop="areaDetailDesc"
          label="所属区域"
          align="center"
          :formatter="formatTd"
        ></el-table-column>
        <el-table-column
          prop="industryName"
          label="行业"
          align="center"
          :formatter="formatTd"
        ></el-table-column>
        <el-table-column
          prop="bankName"
          label="开户银行"
          align="center"
          :formatter="formatTd"
        ></el-table-column>
        <el-table-column label="专户账号" align="center" :formatter="formatTd">
          <template slot-scope="scope">
            <span v-if="scope.row.account">{{
              scope.row.account.replace(
                /^([\s\S]{3})[\s\S]*?([\s\S]{3})$/,
                '$1**** ****$2'
              )
            }}</span>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column label="应发/到账工资总额(元)" align="center">
          <template slot-scope="scope">
            <p>
              ￥{{ scope.row.shouldPay || '0' }}/￥{{
                scope.row.bankActPay || '0'
              }}
            </p>
          </template>
        </el-table-column>
        <el-table-column label="应发/到账总人次" align="center">
          <template slot-scope="scope">
            <p>
              {{ scope.row.shouldPayTotal || '0' }}/{{
                scope.row.bankActPayTotal || '0'
              }}
            </p>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="left" fixed="right">
          <template slot-scope="scope">
            <el-link
              type="primary"
              v-if="isShowDetail"
              @click="toDetail(scope.$index, scope.row)"
              >查看详情</el-link
            >
            <span v-else>--</span>
          </template>
        </el-table-column>
        <!-- 表格数据为空时，页面显示 -->
        <div slot="empty" v-show="isShow">
          <emptyTable emptyText="暂无相关信息"></emptyTable>
        </div>
      </el-table>
      <Pagination
        ref="pagination"
        @getList="getTableList"
        :filterField="filterField"
        :requestUrl="requestUrl"
      ></Pagination>
    </div>
  </div>
</template>

<script>
import { mapActions, mapState } from 'vuex'

export default {
  name: 'salaryPayList',
  components: {},
  data() {
    return {
      titleText: '工资代发',
      //表格数据
      tableList: [],
      requestUrl: 'api-su/cs/salarystats/expand/list',
      areaId: '',
      bankOptions: [],
      //搜索条件
      filterField: {
        projectName: '', //项目名称
        areaId: '', //区域
        industryId: '', //行业
        account: '', //专户账号
        bankId: '', //银行
        serverArea: '', // 服务部署区域
      },
      isShow: false, //列表加载
      loading: true,
      isShowDetail: '',
      bankId: '',
    }
  },
  computed: { ...mapState(['areasOptions', 'industryOptions']) },

  created() {
    this.getBank()
    this.getUserType()
    this.getAreas({ areaId: this.$store.state.areaInfoArr.areaId })
    this.$nextTick(function () {
      this.$refs.pagination.getTableListData()
    })
    this.getIndustry({})
    this.filterField.serverArea = this.$store.state.areaInfoArr.areaId
    this.isShowDetail =
      this.$store.state.buttonLimitsArr.indexOf('bankSalaryPayList:detail') >
        -1 ||
      this.$store.state.buttonLimitsArr.indexOf('mCsSalaryList:detail') > -1
  },
  methods: {
    ...mapActions(['getAreas', 'getIndustry']),
    getBank() {
      var data = {
        type: 'BANK_TYPE',
      }
      this.axios({
        method: 'post',
        url: 'api-bs/base/dicitem/findbytype',
        data: data,
      })
        .then((response) => {
          this.bankOptions = []
          if (this.bankId) {
            for (let i = 0; i < response.data.result.length; i++) {
              let bank = response.data.result[i]
              if (this.bankId == bank.code) {
                this.bankOptions.push(bank)
              }
            }
          } else {
            this.bankOptions = response.data.result
          }
        })
        .catch((error) => {
          console.log(error)
        })
    },
    getTableList(data) {
      this.tableList = data
      this.loading = false
      if (this.tableList.length < 1) {
        this.isShow = true
      }
    },
    //获取选中的区域最后一级id
    getAreaId() {
      var areaId = this.areaId[this.areaId.length - 1]
      this.filterField.areaId = areaId
    },

    // 搜索
    searchList() {
      this.$refs.pagination.getTableListData()
    },
    //跳转详情
    toDetail(index, row) {
      this.$router.push({
        path: '/home/salaryDf/salaryPayBatchList',
        name: 'salaryPayBatchList',
        query: {
          projectId: row.projectId,
          projectName: row.projectName,
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/salaryDf/salaryPayList',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
    getUserType() {
      this.axios({
        method: 'get',
        url: 'api-u/users/current',
      })
        .then((response) => {
          //用户类型
          this.bankId = response.data.bankId
          this.getBank()
        })
        .catch((resp) => {})
    },
  },
}
</script>

<style scoped lang="less">
.topTitle {
  height: 67px;
  background-color: #e4ebf1;
  padding-left: 24px;
  font: bold 18px/67px Microsoft YaHei;
}
.mainCon {
  top: 198px;
}
@media only screen and (max-width: 1366px) {
  /deep/.searchInputWidth .el-form--inline .el-form-item__label {
    width: 80px;
  }
}
</style>
